#ifndef MEM_MANG_H
#define MEM_MANG_H

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include "open_protocol_tiny_port.h"

#define HEAP_ASSERT(x)

#ifndef TOTAL_HEAP_SIZE
#define TOTAL_HEAP_SIZE (3 * 1024)
#endif

/* must be power of 2, at least 8 */
#define BYTE_ALIGNMENT (8)
#define BYTE_ALIGNMENT_MASK (BYTE_ALIGNMENT - 1)
#define POINTER_SIZE_TYPE unsigned int

/* A few bytes might be lost to byte aligning the heap start address. */
#define ADJUSTED_HEAP_SIZE (TOTAL_HEAP_SIZE - BYTE_ALIGNMENT)

/* using disable interrupt to protect */
#define MUTEX_DECLARE(mutex) OPEN_PROTOCOL_MUTEX_DECLARE(mutex)
#define MUTEX_INIT(mutex) OPEN_PROTOCOL_MUTEX_INIT(mutex)
#define MUTEX_LOCK(mutex) OPEN_PROTOCOL_MUTEX_LOCK(mutex)
#define MUTEX_UNLOCK(mutex) OPEN_PROTOCOL_MUTEX_UNLOCK(mutex)

void *heap_malloc(uint32_t wanted_size);
void heap_free(void *pv);
uint32_t heap_get_free(void);
uint32_t heap_get_ever_free(void);
#if 0
void heap_print_block(void);
#endif

#endif
